<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<title>论坛热帖</title>
	<link href="css/css.css" rel="stylesheet" type="text/css">
</head>

<body>
	<header>
		<div class="head_c">
			<!--头部-->
			<div class="top">
				<div class="top_left">欢迎光临悠游行！</div>
				<div class="top_right" style="display: flex;" id="login_signup_area">
					<div class="top_right"><a href="login.html">登录</a><a href="zhuce.html">注册</a></div>
				</div>
				<div class="top_right" style="display: flex;" id="logout_area">
					<a class="top_right" id="login_info" style="font-weight: bold;">用户：15159241643</a>
					<div class="top_right logout_button" onclick="logout()">退出登录</div>
				</div>
			</div>
		</div>
	</header>

	<!--导航-->
	<nav>
		<ul>
			<li><a href="index.html">网站首页</a></li>
			<li><a href="jingdian.html">著名景点</a></li>
			<li><a href="luxian.html">推荐路线</a></li>
			<li><a href="jiudian.html">酒店入住</a></li>
			<li class="on"><a href="luntan.html">论坛热帖</a></li>

		</ul>
	</nav>

	<!--banner-->
	<div class="banner"></div>
	<div class="luntan2">
		<span>请在这里输入标题</span>
		<input type="text" id="post_title" class="title_input">
		<span>请在这里输入正文</span>
		<textarea class="pl_nr" id="post_content"></textarea>
		<button class="show-modal" style="margin: 20px 500px;" onclick="post_paper()">发布</button>
	</div>
	<footer>悠游行</footer>
</body>

<div class="modal-wrapper hidden" id="float_area">
	<div class="modal">
		<h2 style="width:100%; text-align:center; line-height:40px;" id="text_float"></h2>
		<button style="margin: 25px auto 0px auto; justify-self: center;" id="text_float_close"
			onclick="float_area_close()">关闭</button>
	</div>
</div>

</html>
<script src="./js/utils.js"></script>
<script>
	display_login_info();
	if (!hasCookie("token")) {
		window.location.href = "login.html";
	}
	async function post_paper() {
		title = document.querySelector("#post_title").value;
		content = document.querySelector("#post_content").value;
		if (title == "" || content == "") {
			show_float_text("标题或内容不能为空");
			return;
		}
		api = baseUrl2 + "/post/add-post";
		data = {
			title: title,
			content: content
		};
		await fetch(api, {
			method: "POST",
			headers: {
				"Content-Type": "application/json",
				"Authorization": getCookieValue("token"),
			},
			body: JSON.stringify(data)
		}).then(response => response.json())
			.then(data => {
				console.log(data);
				if (data["code"] == 200) {
					show_float_text("发布成功！");
				} else {
					show_float_text("上传文章出现错误");
				}
			}).catch(error => {
				console.error(error);
			})
	}
</script>